<?php
/**
 * Winner
 * 
 * @author Eric
 * @version 
 */
require_once 'Zend/Db/Table/Abstract.php';
class Application_Model_Winner extends Zend_Db_Table_Abstract {
	
	/**
	 * The default table name 
	 */
	protected $_name = 'winner';
	
	// 父表
	protected $_referenceMap = array(
		'user' => array(
			'columns' => array('user_id'),
           	'refTableClass' => 'Application_Model_User',
           	'refColumns' => array('id'),
           	'onUpdate' => self::CASCADE, //更新主表记录时是否更新关联记录
    	),
    	'auction' => array(
			'columns' => array('auction_id'),
           	'refTableClass' => 'Application_Model_Auction',
           	'refColumns' => array('id'),
           	'onUpdate' => self::CASCADE, //更新主表记录时是否更新关联记录
    	)
    );
	
	public function getRecentWinner($count) {
		
		$order = "deal_time desc";
		
		$rows = $this->fetchAll("1=1", $order, $count);
		return $rows; 
	}
	
	public function getWinner($count, $offset) {
		
		$order = "deal_time asc";
		
		$rows = $this->fetchAll("1=1", $order, $count, $offset);
		return $rows;
	}
	
	public function getWinnerNum() {
		
		$sql = "select count(*) as winner_num from winner";
		
		$db = $this->getAdapter();
		$rows = $db->fetchAll($sql);
		
		return $rows; // array
	}
}
